<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title>百媚后花园</title>
    <script src="../base/js/jquery-1.10.2.js"></script>
    <link rel="stylesheet" href="../base/css/weui.css">
    <style>
        body {
            background-color: #fbf9fe;
        }
        .page_title {
            text-align: center;
            font-size: 34px;
            color: #3cc51f;
            font-weight: 400;
            margin: 20px 15% 0;
        }

        .m{
            margin-top: 40px;
            max-width: 1000px;
            margin: 0 auto;
        }
    </style>
</head>
<body ontouchstart="">
    <h1 class="page_title">静态图片页面地址生成</h1>

    <section class="m">
        <div class="weui_cells weui_cells_form">

            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">*标题</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input class="weui_input" type="text" placeholder="请输入标题" data-target="native" data-key="title">
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">*背景图地址</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input class="weui_input" type="text" placeholder="请输入背景图地址" data-target="url" data-key="background">
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">分享参数<br>(extCode)</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input class="weui_input" type="text" placeholder="请输入extCode" data-target="url" data-key="extCode">
                </div>
            </div>
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">背景颜色</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input class="weui_input" type="text" placeholder="请输入背景颜色值（不用带#号）" data-target="url" data-key="bgColor">
                </div>
            </div>
        </div>
        <div class="weui_cells_tips">带 * 为必填项</div>
        <div class="weui_btn_area">
            <a class="weui_btn weui_btn_primary" href="javascript:" data-action="bmlive://bmlive/web">生成地址并复制</a>
        </div>
        <div class="weui_cells weui_cells_form">
            <div class="weui_cell">
                <div class="weui_cell_hd"><label class="weui_label">最终地址</label></div>
                <div class="weui_cell_bd weui_cell_primary">
                    <input class="weui_input" type="text" id="J_result" placeholder="准备复制这里">
                </div>
            </div>
            <div class="weui_btn_area">
                <a class="weui_btn weui_btn_primary" href="javascript:" id="J_go">去看看</a>
            </div>
        </div>
    </section>
    <script>
        $(function () {
            var result = '';
            $('.m').each(function  () {
                var $this = $(this);
                $this.find('[data-action]').on('click', function(event) {
                    event.preventDefault();
                    var arr = [];
                    var title = '';
                    var url = $(this).data('action');

                    $this.find('[data-target]').each(function (num) {
                        var item = $(this);
                        var value = '';
                        var key = item.data('key');

                        if(!key) return;

                        switch(item.data('target')) {
                            case 'url':
                                value = item.val();
                                break;

                            case 'native':
                                title = item.val();
                                break;
                        }

                        if(value !== '') {
                            arr.push(key+'='+value);
                        }
                    })
                    result = url+'?title='+title+'&url='+encodeURIComponent('http://h5.chinaqljf.com/static_page/index.html?'+arr.join('&'));
                    $('#J_result').val(result); 
                    $('#J_result').select();
                    try {
                        document.execCommand("copy",false,null);
                    }
                    catch(e) {
                        alert('请使用ctrl+c或者长按来进行复制');
                    }
                });
            })

            $('#J_result').on('focus', function() {
                $(this).select();
            });

            $("#J_go").on('click', function() {
                window.location.href=result;
            });
        })
    </script>
</body>
</html>
